home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 02 Useful Techniques / 08 Zarozinski / src / Sample Program / AIWisdom.cpp
Encoding:
C/C++ Source or Header  |  2001-12-08  |  2.1 KB  |  93 lines

  1. //
  2. // File:    AIWisdom.cpp    
  3. //
  4. // Purpose:    Test program for FFLL API
  5. //
  6. // Copyright ⌐ 2001 Louder Than A Bomb! Software
  7. //
  8. //
  9. //
  10.  
  11. #include "FFLLAPI.h"    // FFLL API
  12. #include <iostream.h>    // for i/o functions
  13.  
  14. #define OUR_HEALTH    0 // our health is 1st variable
  15. #define ENEMY_HEALTH    1 // enemy health is 2nd variable
  16.  
  17. int main(int argc, char* argv[])
  18. {
  19.     float    our_health, enemy_health; // values for input variables
  20.     char    option;    // var for selection of what user wants to do
  21.  
  22.     cout.setf(ios::fixed);
  23.     cout.precision(2); // only display 2 decimal places
  24.  
  25.     // create and load the model
  26.     int model = ffll_new_model();  
  27.  
  28.     int ret_val = (int)ffll_load_fcl_file(model, "..\\aiwisdom.fcl");  
  29.  
  30.     if (ret_val < 0)
  31.         {
  32.         cout << "Error Opening aiwisdom.fcl";
  33.         // make sure the "working directory" in "Project | Settings..."
  34.         // is set to the executable's directory if running from the MSVC IDE
  35.         return 0;
  36.         }
  37.  
  38.     // create a child for the model...
  39.     int child = ffll_new_child(model);
  40.  
  41.     while (1)
  42.         {
  43.         cout << "SELECT AN OPTION:\n\tS - set values\n\tQ - quit";
  44.         cout << endl;
  45.         cin >> option;
  46.  
  47.         if (option == 'Q' || option == 'q')
  48.             break;
  49.  
  50.         if (option == 'S' || option == 's')
  51.             {
  52.             cout << "Our Health: " ;
  53.             cin >> our_health;
  54.             cout << "Enemy's Health: "  ;
  55.             cin >> enemy_health;
  56.             cout << "Aggressiveness: ";
  57.  
  58.             // set input variables...
  59.  
  60.             ffll_set_value(model, child, OUR_HEALTH, our_health); 
  61.             ffll_set_value(model, child, ENEMY_HEALTH, enemy_health);
  62.  
  63.             // get and display the output value
  64.             int output = (int)ffll_get_output_value(model, child);
  65.  
  66.             switch(output)
  67.                 {
  68.                 case (1):
  69.                     cout << "Run Away!";
  70.                     break;
  71.  
  72.                 case (2):
  73.                     cout << "Fight Defensively";
  74.                     break;
  75.  
  76.                 case (3):
  77.  
  78.                     cout << "All Out Attack!";
  79.                     break;
  80.  
  81.                 } // end switch
  82.  
  83.             cout << endl;
  84.             } // end if option = 's'
  85.  
  86.         } // end while(1)
  87.  
  88.     return 0;
  89.  
  90. } // end main()
  91.  
  92.   
  93.